All Questions
Tagged with c++17template-meta-programming
58 questions
4votes
2answers
447views
Compile time string manipulation in C++
I recently had to work on some conversion of literal strings and wondered if that could be done at compile time using template meta programming. I couldn't find many examples online, so I started ...
7votes
2answers
215views
Function composition in the context of data processing pipelines
Prior Notification This follows a previous review of mine that addressed the core helper function named make_skippable. The composition implementation presented ...
3votes
2answers
140views
Extending callable signature with std::optional in context of function composition (make_skippable)
(Please note: the post about the compose implementation announced below is now available.) This is about decorating callables by making their argument and return value to be a ...
4votes
0answers
54views
Variadic pack class providing operations over types without constructing objects of those types
Sometimes I find I want to call a function passing each of a set of types as a template parameter, but without needing to construct an object of those types. I also may want to do this in multiple ...
4votes
1answer
2kviews
Template to unpack arguments to a std::function
I am writing some C++ code to interact with an external scripting language. I want to be able to register arbitrary C++ callable code as functions to be called from the script. The scripting library ...
2votes
1answer
204views
C++17 view over the Ith elements of tuples in containers of tuples
For mainly didactic reasons, I have designed my ElementsView<I, T> class template, which provides a view over the I th ...
3votes
1answer
2kviews
visit for std::any
While solving an online excersise I have written some basic implementation for a visit function that works with std::any. The ...
1vote
2answers
907views
Automatically registering a class using header-only templated classes
I'm trying to reduce the boilerplate of a lot of header-only classes I'm using. Each of these classes must go through a registration step. I want this step to be defined in the same file as the class ...
1vote
1answer
1kviews
A multi key/value type "folded" map class template
I have recently come across a use case where I need to lump many maps into a single container. These maps can have different combinations of key/value types, but they all differ from one another. For ...
4votes
3answers
4kviews
De-/Serialization of structs representing TCP messages
I wrote two template functions to serialize and deserialize structs representing messages to be sent and received via a TCP socket: ...
7votes
1answer
508views
Generic test case templates
I often find that when I am writing, refactoring, or reviewing code that I want to do some simple testing. There are many existing test frameworks such as gtest and cppunit but my desire was to ...
4votes
1answer
397views
Template Metaprogramming and Modular Arithmetic
Story I'm trying to become more familiar with template metaprogramming and practice more of it. I need to use modular arithmetic to solve certain problems and so I decided to write a general purpose ...
4votes
1answer
722views
Template Metaprogramming - Multidimensional Vector Declaration
[EDIT] The question has been edited. Please make sure to read the summary at the end of the post. If you'd like me to make a new post with a cleaner explanation and better examples, tell me to do so ...
3votes
0answers
66views
Getting around gsl/span's restriction on temporaries
The goal of this code is to allow temporary RHS variables to be used in a span, specifically as an argument to a function, to be deleted later after the function completes, allowing the passing of ...
4votes
0answers
1kviews
A wrapper for (perfect forwarding + initialization)
Problem Perfect forwarding is known to be imperfect when it comes to list-initialization; I'll use std::construct_at as an example: ...